home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / Telnet 2.5.src.ThinkC / source / NCSA Driver / Assembly.c < prev    next >
Encoding:
Text File  |  1990-08-28  |  10.2 KB  |  449 lines  |  [TEXT/KAHL]

  1. /**********************************************************************************
  2.  
  3.                                 Assembly.c
  4.                                 
  5.                 This file contains the three assembly files, (cksum.a,
  6.                 elistener.a, and listener.a) as one C file, so that the 
  7.                 assembly can be put into the project file as in-line
  8.                 assembly code.   
  9.                             - Rob Clawson, 8/17/90
  10.                             
  11. ***********************************************************************************/                            
  12.  
  13.  
  14. /***********************************************************************************
  15.                                     cksum.a
  16. ***********************************************************************************/
  17.  
  18. /*
  19.  
  20.     blanks off
  21.     case on  */
  22.     
  23. /************************************************************************************/
  24.  
  25. /*;    public _ipcheck,_tcpcheck
  26. ipcheck    PROC    EXPORT         ; (integer) sum = ipcheck(buf:Ptr, wdcnt:integer)  */
  27. ipcheck(void *param1,int param2) 
  28. {
  29. asm {
  30.      clr.l     d1
  31.      move.l    8(sp),d1            ; move w on Aztec (16b) move l on MPW (32b)
  32.      move.l    4(sp),a0
  33.      subq.l    #1,d1
  34.      clr.l     d0
  35. again
  36.      add.w     (a0)+,d0
  37.      bcc.s     nocar
  38.      addq.w    #1,d0
  39. nocar
  40.      dbra      d1,again
  41.      andi.w       #$0ffff,d0
  42.      eori.w       #$0ffff,d0
  43.      rts
  44.      }
  45. /*    ENDPROC  */
  46.  
  47. }  /* End ipcheck */
  48.  
  49. /**********************************************************************************/
  50. /*    
  51. tcpcheck    PROC  EXPORT            ; (integer) sum = tcpcheck(phd: Ptr,buf:Ptr, btcnt:integer) */
  52. tcpcheck(void *param1, void *param2, int param3)
  53. {
  54. asm {
  55.      clr.l     d1
  56.      clr.l     d0
  57.      move.l       4(sp),a0
  58.      moveq     #5,d1
  59. again2                ; check the 12 byte pseudo header.
  60.      add.w     (a0)+,d0
  61.      bcc.s     nocar2
  62.      addq.w    #1,d0
  63. nocar2
  64.      dbra      d1,again2
  65.  
  66.      move.l    8(sp),a0
  67.      move.l    12(sp),d1            ; move w on Aztec (16b) move l on MPW (32b)
  68.      asr.w       #1,d1
  69.      bcc.s       onward
  70.      move.l       12(sp),d2
  71.      clr.b       0(a0,d2)
  72.      addq.w       #1,d1
  73. onward
  74.      subq.w       #1,d1
  75. again3
  76.      add.w     (a0)+,d0
  77.      bcc.s     nocar3
  78.      addq.w    #1,d0
  79. nocar3
  80.  
  81.      dbra      d1,again3
  82. tcpend
  83.      andi.w       #$0ffff,d0
  84.      eori.w       #$0ffff,d0
  85.      rts
  86.     }
  87. /*    ENDPROC
  88.     
  89.     END
  90.     */
  91. } /* End tcpcheck */
  92.  
  93. /***********************************************************************************
  94.                             elistener.a
  95. ***********************************************************************************/
  96. /*;        The NCSA Socket Listener.  For use with NCSA's TCP/IP Implementation
  97. ;    developed in 1986 by Tim Krauskopf and Gaige Paulsen.
  98. ;    
  99. ;
  100. ;        Well, that nutty Gaige guy decided one day to make this little pile
  101. ;    work with EtherTalk....... here are the results.
  102. ;
  103. ;        The Socket Listener is passed as a parameter to the DDPOpen Call for
  104. ;     AppleTalk.  At this time, all packets received for that socket are passed
  105. ;    to said socket listener instead of causing events.
  106. ;
  107.  
  108.     blanks off
  109.     case on
  110. */
  111. /****    Should I make all of these #defines?  ****/
  112.  
  113. #define    AB_IP_Socket        72
  114. #define    ETtype            -2        
  115. #define    ETfrom            -8        
  116. #define    ETto                -14        
  117. #define    ETaddr1            -6
  118. #define    ETaddr2            -10
  119. #define    ETaddr3            -14
  120. #define    ET_IP            $0800
  121. #define    ET_ARP            $0806
  122. #define    ET_RARP            $8035
  123. #define    dLAYER            16        
  124. #define    IPProt            -2        
  125. #define    IPLen            -16         
  126. #define    bufpt            0
  127. #define    bufread            4
  128. #define    buforg            8
  129. #define    bufend            12
  130. #define    bufbig            16
  131. #define    buflim            18
  132.  
  133. /*   This is just the old stuff */
  134. AB_IP_Socket        EQU        72
  135. ETtype            EQU        -2        Relative to the wild and wonderful A3
  136. ETfrom            EQU        -8        Ditto, but prolly unused
  137. ETto                EQU        -14        ditto that previous ditto
  138. ETaddr1            EQU        -6
  139. ETaddr2            EQU        -10
  140. ETaddr3            EQU        -14
  141. ET_IP            EQU        $0800
  142. ET_ARP            EQU        $0806
  143. ET_RARP            EQU        $8035
  144. dLAYER            EQU        16        Get the size from C please! (Just did....)
  145. IPProt            EQU        -2        Not Actually the IP protocol --dlayer....
  146. IPLen            EQU        -16         I Think
  147. bufpt            EQU        0
  148. bufread            EQU        4
  149. buforg            EQU        8
  150. bufend            EQU        12
  151. bufbig            EQU        16
  152. buflim            EQU        18        */
  153. /*;
  154. ;
  155. ;        PUBLIC    _ETListen,_ETInitBufPtr
  156. ;
  157.  
  158. _Debugger             OPWORD            $A9FF
  159.  
  160. ETnastyhack    PROC    EXPORT
  161.  
  162. DEAF    DC.W    0
  163. bufptrs    DC.L    0
  164. badrecv    DC.L    0
  165. */
  166.         EXPORT ETInitBufPtr
  167.         EXPORT ETListen
  168.         EXPORT ETdeafreset
  169.         
  170. /*ETdeafreset  */
  171. ETdeafreset()
  172. {
  173. asm {
  174.         LEA        DEAF,A0                return deaf flag value
  175.         MOVEQ.L    #0,D0
  176.         MOVEQ.L    #0,D1
  177.         MOVE.W    0(A0),D0            return DEAF value
  178.         MOVE.W    D1,0(A0)            set deaf back off
  179.         RTS
  180.     }
  181. } /* End ETdeafreset */
  182.  
  183. /*ETInitBufPtr    */
  184. ETInitBufPtr(void *param1)
  185. {
  186. asm {
  187.         LEA        bufptrs,A0            return where we store bufinfo record pointer
  188.         MOVE.L    4(SP),D0
  189.         MOVE.L    D0,0(A0)
  190.         RTS
  191.     }
  192. } /* End ETInitBufPtr */
  193.  
  194. /*ETListen */
  195. ETListen()
  196. {
  197. asm {
  198.         LEA        DEAF,A5
  199.         TST.W    0(A5)
  200.         BEQ.s    Hearing                Not deaf, keep going
  201.  
  202.         BRA.S    RecvFail            Deaf, skip over
  203.         
  204. ;        _Debugger
  205. ;        MOVEQ    #0,D3
  206. ;        MOVE.W    D3,0(A5)            Resume hearing
  207. ;        MOVE.L    bufptrs,A5            base for pointers 
  208. ;        MOVE.L    buforg(A5),D2    
  209. ;        MOVE.L  D2,bufread(A5)      Set to beginning of buffer
  210. ;        MOVE.L  D2,bufpt(A5)           ditto
  211. ;        MOVE.W    D3,bufbig(A5)       pretend nothing is in buffer
  212.                                     ;fall through to hearing
  213. Hearing
  214.         MOVE.W    ETtype(A3),D0        Ok, this is our type
  215. Got_Prot                            ;Left in for historical purposes
  216.         CMPI.W    #ET_IP,D0
  217.         BEQ.S    GoodProt
  218.         CMPI.W    #ET_RARP,D0
  219.         BEQ.S    GoodProt
  220.         CMPI.W    #ET_ARP,D0
  221.         BNE.s    RecvFail            Well, I only want these......
  222. GoodProt
  223.         MOVE.L    bufptrs,A5
  224.         MOVE.L    bufpt(A5),A2
  225.         MOVE.W    bufbig(A5),D2
  226.         CMP.W    buflim(A5),D2        Used to be CMP.L (6/15/89 - TK)
  227.         
  228.         BGE.S    GoDeaf                Im full.  More = tummy ache
  229.  
  230.         MOVE.L    A2,D2                Save it for later (post ReadRest)
  231.         ADDA    #dLAYER,A2
  232.         MOVE.W    D0,IPProt(A2)        Move the protocol into the header
  233.         MOVE.L    ETaddr1(A3),ETaddr1(A2)        Ok, move the header
  234.         MOVE.L    ETaddr2(A3),ETaddr2(A2)        One piece at a time
  235.         MOVE.L    ETaddr3(A3),ETaddr3(A2)        Are we having fun?
  236.         MOVE.W    D1,IPLen(A2)        Move the suggested retail length into the header
  237.         MOVE.W    D1,D3                We need to know if we read the right amount
  238.         MOVEA.L    A2,A3
  239.         JSR        2(A4)                Read Rest Now
  240.  
  241.         TST.W    D3                    If this is zero we are OK
  242.         BNE.s    SRoll                This is bad
  243.         MOVE.L    bufptrs,A0
  244.         MOVE.L    A3,D3
  245.         MOVE.L    D3,D1                Our Temporary Space
  246.         SUB.L    D2,D1                D2 was the previous A3
  247.         ADD.W    D1,bufbig(A0)        Now increment bufbig
  248.         ADDQ.L    #1,D3                And Adjust for even/odd buffering
  249.         BCLR    #0,D3
  250.  
  251.         CMP.L    bufend(A0),D3        Check for Wraparound on end of buffer
  252.         BLE.S    UpdatePt
  253.         MOVE.L    buforg(A0),D3
  254. UpdatePt
  255.         MOVE.L    D3,bufpt(A0)        And Update Buf Pointer
  256.         RTS                            Terminate (one way or another)
  257. RecvFail
  258.         MOVEQ    #0,D3                Trash the packet
  259.         JMP        2(A4)
  260.  
  261. GoDeaf
  262.         MOVEQ    #1,D3
  263.         LEA        DEAF,A5
  264.         MOVE.W    D3,0(A5)
  265.         BRA.s        RecvFail
  266.  
  267. UnDeaf                            
  268.         MOVEQ    #0,D3            Be Careful    A5 used here    
  269.         LEA        DEAF,A5
  270.         MOVE.W    D3,0(A5)
  271.         RTS
  272.  
  273. SRoll
  274.         LEA        badrecv,A0
  275.         ADDQ.L    #1,0(A0)
  276.         RTS
  277.     }
  278. } /* End ETListen */
  279.  
  280. /*
  281.         ENDPROC
  282.         
  283.         END
  284.         */
  285. /***********************************************************************************
  286.                                     listener.a
  287. ************************************************************************************/
  288. /*;        The NCSA Socket Listener.  For use with NCSA's TCP/IP Implementation
  289. ;    developed in 1986 by Tim Krauskopf and Gaige Paulsen.
  290. ;    
  291. ;        The Socket Listener is passed as a parameter to the DDPOpen Call for
  292. ;     AppleTalk.  At this time, all packets received for that socket are passed
  293. ;    to said socket listener instead of causing events.
  294. ;
  295. ;
  296. ;        dLAYER changed to add more padding (gotta make it enet size, y'know
  297. ;
  298.     blanks off
  299.     case on
  300. */
  301. /****     Should I make all of these #defines?  *****/
  302.  
  303. /*#define    AB_IP_Socket            72    defined above     */
  304. #define    toRHA                -5
  305. #define    shortDDP                1
  306. #define    lapType                8
  307. #define    lapHdSz                3
  308. #define    sDDPType                10
  309. #define    ddpType                18
  310. #define    AB_IP                22
  311. #define    AB_ARP                23
  312. /*#define    dLAYER                14        defined above, renamed below     */    
  313. /*#define    IPProt                -4        defined above, renamed below     */    
  314. /*#define    IPLen                -14         defined above, renamed below     */    
  315. #define    AB_dLAYER                14            
  316. #define    AB_IPProt                -4
  317. #define    AB_IPLen                -14             
  318. /*#define    bufpt                0        defined above     */
  319. /*#define    bufread                4        defined above     */
  320. /*#define    buforg                8        defined above     */
  321. /*#define    bufend                12        defined above     */
  322. /*#define    bufbig                16        defined above     */
  323. /*#define    buflim                18        defined above     */
  324.  
  325. /*  These are just the old ones  */
  326. AB_IP_Socket        EQU        72
  327. toRHA            EQU        -5
  328. shortDDP            EQU        1
  329. lapType            EQU        8
  330. lapHdSz            EQU        3
  331. sDDPType            EQU        10
  332. ddpType            EQU        18
  333. AB_IP            EQU        22
  334. AB_ARP            EQU        23
  335. dLAYER            EQU        14        Get the size from C please!
  336. IPProt            EQU        -4
  337. IPLen            EQU        -14         I Think
  338. bufpt            EQU        0
  339. bufread            EQU        4
  340. buforg            EQU        8
  341. bufend            EQU        12
  342. bufbig            EQU        16
  343. buflim            EQU        18
  344. /*;
  345. ;
  346. ;        PUBLIC    _Listen,_InitBufPtr
  347.  
  348. ATnastyhack    PROC    EXPORT
  349.  
  350. DEAF    DC.W    0
  351. bufptrs    DC.L    0
  352. badrecv    DC.L    0
  353.  
  354.         EXPORT Listen
  355.         EXPORT InitBufPtr
  356. */
  357. /*InitBufPtr  */
  358. InitBufPtr(void *param1)
  359. {
  360. asm {
  361.         LEA        bufptrs,A0
  362.         MOVE.L    4(SP),D0
  363.         MOVE.L    D0,0(A0)
  364.         RTS
  365.     }
  366. } /* End InitBufPtr */
  367.  
  368.  
  369. /*Listen */
  370. Listen()
  371. {
  372. asm {
  373.         LEA        DEAF,A5
  374.         TST.W    0(A5)
  375.         BNE.s        RecvFail
  376. Hearing
  377.         CMPI.B    #AB_IP_Socket,D0    Is it for me?
  378.         BEQ.S    MySocket            Yep
  379.         BRA.S        RecvFail            No Throw it out!
  380. MySocket
  381.         LEA        toRHA(A2),A3        a3 now is LAP Header
  382.         CMPI.B    #shortDDP,lapType(A3)
  383.         ADDQ.L    #lapHdSz,A3
  384.         BNE.S    LongDDP
  385.         MOVE.B    sDDPType(A3),D0        D0 = protocol type
  386.         BRA.S    Got_Prot            Ive got it
  387. LongDDP
  388.         MOVE.B    ddpType(A3),D0
  389. Got_Prot
  390.         CMPI.B    #AB_IP,D0
  391.         BEQ.S    GoodProt
  392.         CMPI.B    #AB_ARP,D0
  393.         BNE.S        RecvFail
  394. GoodProt
  395.         MOVE.L    bufptrs,A5
  396.         MOVE.L    bufpt(A5),A3
  397.         MOVE    bufbig(A5),D2
  398.         CMP.L    buflim(A5),D2
  399.         BGE.S    GoDeaf                Im full.  More = tummy ache
  400.  
  401.         MOVE.L    A3,D2                Save it for later (post ReadRest)
  402.         ADDA    #AB_dLAYER,A3
  403.         MOVE.B    D0,AB_IPProt(A3)        Move the protocol into the header
  404.         MOVE.W    D1,AB_IPLen(A3)        Move the suggested retail length into the header
  405.         MOVE.W    D1,D3                We need to know if we read the right amount
  406.         JSR        2(A4)                Read Rest Now
  407.  
  408.         TST.W    D3                    If this is zero we are OK
  409.         BNE.s    BadPkt            This is bad
  410.         MOVE.L    bufptrs,A0
  411.         MOVE.L    A3,D3
  412.         MOVE.L    D3,D1                Our Temporary Space
  413.         SUB.L    D2,D1                D2 was the previous A3
  414.         ADD.W    D1,bufbig(A0)        Now increment bufbig
  415.         ADDQ.L    #1,D3                And Adjust for even/odd buffering
  416.         BCLR    #0,D3
  417.  
  418.         CMP.L    bufend(A0),D3        Check for Wraparound on end of buffer
  419.         BLE.S    UpdatePt
  420.         MOVE.L    buforg(A0),D3
  421. UpdatePt
  422.         MOVE.L    D3,bufpt(A0)        And Update Buf Pointer
  423.         RTS                            Terminate (one way or another)
  424. RecvFail
  425.         MOVEQ    #0,D3                Trash the packet
  426.         JMP        2(A4)
  427.  
  428. GoDeaf
  429.         MOVEQ    #1,D3
  430.         LEA        DEAF,A5
  431.         MOVE.W    D3,0(A5)
  432.         BRA.s        RecvFail
  433.  
  434. UnDeaf                            
  435.         MOVEQ    #0,D3            Be Careful    A5 used here    
  436.         LEA        DEAF,A5
  437.         MOVE.W    D3,0(A5)
  438.         RTS
  439.  
  440. BadPkt
  441.         LEA        badrecv,A0
  442.         ADDQ.L    #1,0(A0)
  443.         RTS
  444.     }
  445. } /* End InitBufPtr */
  446. /*        ENDPROC
  447.         
  448.         END
  449.                                                 */